<template>
	<view class="container">
		<view class="subsection_view">
			<u-subsection style=" width: 200px;" :list="subsectionList" :current="curNow" button-color="#324DEC"
				active-color="#FFFFFF" @change="sectionChange"></u-subsection>
		</view>
		<view style="width: 100%;height: 20rpx;"></view>
		<view class="list_view">
			<view class="item_view" v-for="(item,index) in dataList" :key="index" @click="detailAction(item)">
				<view class="left_view">
					<view class="icon_view">
						<image :src="doorIcon" v-if="item.deviceType=='DOOR'" mode=""
							style="border-radius: 10rpx;width: 100%;height: 100%;">
						</image>
						<image v-else-if="item.deviceType=='LOCK'" :src="lockIcon" mode=""
							style="border-radius: 10rpx;width: 100%;height: 100%;">
						</image>
					</view>
					<view class="content_view">
						<view class="title_view Text33" style="margin-bottom: 10rpx;">
							{{item.deviceName}}
						</view>
						<view class="detail_view Text66">
							{{item.area}} | {{item.location}}
						</view>
					</view>
				</view>
				<view class="right_view">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" mode="list" v-if="dataList.length==0" :margin-top="300"></u-empty>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				subsectionList: [{
						name: '待处理'
					},
					{
						name: '已通过'
					},
					{
						name: '已驳回'
					}
				],
				curNow: 0,
				dataList: [],
				tenantName: '',
				tenantId: '',
				status: 1, // 申请状态，1：待审批 2：审批通过 3：审批拒绝4：用户取消
				dataList: [],
				pageNum: 1,
				pageSize: 10,
				total: 0,
				emptyPage: false,
				doorIcon: '/static/images/smartLock/doorIcon.png',
				lockIcon: '/static/images/smartLock/lockIcon.png',
				alarmIcon: '/static/images/smartLock/alarmIcon.png',
			}
		},

		onShow() {
			let sUserInfo = this.$storage.getStorageDataSync("sUserInfo")
			this.tenantId = sUserInfo.tenantId
			this.tenantName = sUserInfo.tenantName
			this.getApproveListData()
		},
		// onBackPress(e) {
		// 	// 这里可以自定义返回逻辑，比如下面跳转其他页面
		// 	console.log('返回-----------')
		// 	uni.reLaunch({
		// 		url: '/pages/smartLock/views/index'
		// 	})
		// 	return true //表示禁止默认返回
		// },
		methods: {
			sectionChange(index) {
				this.curNow = index;
				this.status = index + 1;
				this.getApproveListData()
			},
			detailAction(item) {
				this.$Router.push({
					name: 'approveRecordDetail',
					params: {
						authorizeId: item.id,
						deviceType: item.deviceType,
						status: this.status
					}
				})
			},
			onPullDownRefresh() {
				this.pageNum = 1
				this.getApproveListData()
			},
			onReachBottom() {
				if (this.total <= this.pageNum * this.pageSize) {
					return
				}
				this.pageNum += 1
				this.getApproveListData()
			},
			getApproveListData() {
				var that = this
				this.$apis.getApproveList({
					tenantId: this.tenantId,
					status: this.status,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				}).then(result => {
					uni.stopPullDownRefresh();
					if (result.res.data.code == '200') {
						if (that.pageNum == 1) {
							that.dataList = [] //如果是第一页需手动制空列表
							if (result.res.data.rows.length == 0) that.emptyPage = true
						}
						that.total = result.res.data.total
						that.dataList = that.dataList.concat(result.res.data.rows)
					} else {
						that.$show.toastMessage(result.res.data.msg);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		box-sizing: border-box;
		background-color: #F8F8F8;
	}

	.subsection_view {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;
		padding: 20rpx;
	}

	.list_view {
		padding: 20rpx;
		padding-top: 0;

		.item_view {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			margin: 20rpx 0;
			background-color: #FFFFFF;
			border-radius: 10rpx;

			.left_view {
				display: flex;
				flex-direction: row;
				align-items: center;

				.icon_view {
					width: 100rpx;
					height: 100rpx;
				}

				.content_view {
					margin-left: 20rpx;
				}
			}
		}
	}
</style>